package cn.edu.jxau.service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

public class setMessage {

	public static void setCookies(String username, String password, String flag, HttpServletResponse response) {

		if (flag != null) {
			Cookie name = new Cookie("username", username);
			Cookie pwd = new Cookie("password", password);
			Cookie yes = new Cookie("flag", flag);
			// 设置cookie的最大生存时间
			name.setMaxAge(60 * 60 * 24);
			pwd.setMaxAge(60 * 60 * 24);
			yes.setMaxAge(60 * 60 * 24);

			response.addCookie(name);
			response.addCookie(pwd);
			response.addCookie(yes);
		} else {
			Cookie yes = new Cookie("flag", "no"); // 不记住密码的标志
			response.addCookie(yes);
		}
	}
}
